package com.hualan.zhsq.service.impl.car;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hualan.zhsq.constant.CommonConstant;
import com.hualan.zhsq.entity.car.ParkingSpace;
import com.hualan.zhsq.mapper.car.ParkingSpaceMapper;
import com.hualan.zhsq.service.car.ParkingSpaceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName ParkingSpaceServiceImpl
 * @Description TODO
 * @Author ZheRan
 * @Date 2025年08月05日 下午7:33
 * @Version 1.0
 */
@Service("parkingSpaceService")
public class ParkingSpaceServiceImpl implements ParkingSpaceService {

    @Autowired
    private ParkingSpaceMapper parkingSpaceMapper;

    @Override
    public int add(ParkingSpace entity) {
        return parkingSpaceMapper.insert(entity);
    }

    @Override
    public int edit(ParkingSpace entity) {
        return parkingSpaceMapper.updateById(entity);
    }

    @Override
    public int remove(Integer id) {
        return parkingSpaceMapper.deleteById(id);
    }

    @Override
    public int removeBatch(Integer[] ids) {
        return parkingSpaceMapper.deleteBatchIds(List.of(ids));
    }

    @Override
    public List<ParkingSpace> find() {
        return parkingSpaceMapper.selectList(null);
    }

    @Override
    public Map<String, Object> findPage(Integer pageNum, Integer pageSize, ParkingSpace entity) {
        Page<ParkingSpace> page = new Page<>(pageNum, pageSize);
        QueryWrapper<ParkingSpace> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("del", 0);
        Page<ParkingSpace> parkingSpacePage = parkingSpaceMapper.selectPage(page, queryWrapper);
        Map<String, Object> map = new HashMap<>();
        map.put("list", parkingSpacePage.getRecords());
        map.put("total", parkingSpacePage.getTotal());
        map.put("size", parkingSpacePage.getSize());
        return map;
    }

    @Override
    public ParkingSpace findById(Integer id) {
        return parkingSpaceMapper.selectById(id);
    }


    @Override
    public Map<String, Object> parkingSpaceResident(Integer pageNum,Integer pageSize, ParkingSpace entity) {
        Page<ParkingSpace> page = new Page<>(pageNum, pageSize);
        Page<ParkingSpace> parkingSpacePage = parkingSpaceMapper.selectAllPage(page,entity);

        long total =parkingSpacePage.getTotal();
        long size = parkingSpacePage.getSize();
        List<ParkingSpace> list = parkingSpacePage.getRecords();

        Map<String, Object> map = new HashMap<>();
        map.put("list", list);
        map.put("total", total);
        map.put("size", size);

        return map;
    }
}

